package com.ruoyi.activity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.goods.api.ReSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.activity.domain.BmPreferential;
import com.ruoyi.activity.service.IBmPreferentialService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 优惠活动信息Controller
 *
 * @author ruoyi
 * @date 2023-08-08
 */
@RestController
@RequestMapping("/activity")
public class BmPreferentialController extends BaseController
{
    @Autowired
    private IBmPreferentialService bmPreferentialService;
    @Autowired
    private ReSpecificationService rspecificationService;

    /**
     * 根据商品详情id查询单个商品详情
     */
    @GetMapping("/getSpecificationById")
    public AjaxResult getSpecificationById(@PathVariable("id") Long id) {
        return rspecificationService.getInfo(id);
    }
    /**
     * 查询优惠活动信息列表
     */
    @RequiresPermissions("activity:activity:list")
    @GetMapping("/list")
    public TableDataInfo list(BmPreferential bmPreferential)
    {
        startPage();
        List<BmPreferential> list = bmPreferentialService.selectBmPreferentialList(bmPreferential);
        return getDataTable(list);
    }

    /**
     * 导出优惠活动信息列表
     */
    @RequiresPermissions("activity:activity:export")
    @Log(title = "优惠活动信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmPreferential bmPreferential)
    {
        List<BmPreferential> list = bmPreferentialService.selectBmPreferentialList(bmPreferential);
        ExcelUtil<BmPreferential> util = new ExcelUtil<BmPreferential>(BmPreferential.class);
        util.exportExcel(response, list, "优惠活动信息数据");
    }

    /**
     * 获取优惠活动信息详细信息
     */
    @RequiresPermissions("activity:activity:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bmPreferentialService.selectBmPreferentialById(id));
    }

    /**
     * 新增优惠活动信息
     */
    @RequiresPermissions("activity:activity:add")
    @Log(title = "优惠活动信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmPreferential bmPreferential)
    {
        return toAjax(bmPreferentialService.insertBmPreferential(bmPreferential));
    }

    /**
     * 修改优惠活动信息
     */
    @RequiresPermissions("activity:activity:edit")
    @Log(title = "优惠活动信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmPreferential bmPreferential)
    {
        return toAjax(bmPreferentialService.updateBmPreferential(bmPreferential));
    }

    /**
     * 删除优惠活动信息
     */
    @RequiresPermissions("activity:activity:remove")
    @Log(title = "优惠活动信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bmPreferentialService.deleteBmPreferentialByIds(ids));
    }
}
